//
//  ByOrderCell.m
//  hutouben_ios
//
//  Created by mc on 16/11/30.
//  Copyright © 2016年 mc. All rights reserved.
//

#import "ByOrderCell.h"
@interface ByOrderCell()
{
    UIImageView *_proImgView;
    UILabel *_titleLabel;
    UILabel *_priceLabel;
    UILabel *_accountLabel;
    UIView *_lineView;
}
@end
@implementation ByOrderCell

+ (instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString *cellIdentifier = @"ByOrderCell";
    ByOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        [self setViews];
    }
    return self;
}

#pragma mark ---创建视图
- (void)setViews{
    _proImgView = [[UIImageView alloc] init];
    _proImgView.backgroundColor = HTB_THEME_COLOR;
    [self addSubview:_proImgView];
    
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.textColor = HTB_TEXT_COLOR2;
    _titleLabel.font = FONT(14);
    _titleLabel.numberOfLines = 2;
    [self addSubview:_titleLabel];
    
    _priceLabel = [[UILabel alloc] init];
    _priceLabel.textColor = HTB_THEME_COLOR;
    _priceLabel.font = FONT(14);
    [self addSubview:_priceLabel];
    
    _accountLabel = [[UILabel alloc] init];
    _accountLabel.textColor = HTB_THEME_COLOR;
    _accountLabel.font = FONT(14);
    [self addSubview:_accountLabel];
    
    _lineView = [[UIView alloc] init];
    _lineView.backgroundColor = HTB_LINE_COLOR;
    [self addSubview:_lineView];

}

-(void)setItemModel:(ByNetOrderItemModel *)itemModel{
    _itemModel = itemModel;
    
    //图片
    CGFloat x,y,width,height;
    x = 10;
    y = 10;
    width = height = 80;
    _proImgView.frame = CGRectMake(x, y, width, height);
    
    //title
    x = _proImgView.right + 10;
    width = SCREEN_WIDTH - x - 10;
    height = [_itemModel.name getRectOfStringWithSize:CGSizeMake(width, MAXFLOAT) font:14].size.height;
    _titleLabel.frame = CGRectMake(x, y, width, height);
    _titleLabel.text = _itemModel.name;
    
    //数量
    y = _proImgView.bottom - 20;
    NSString *accountStr = [NSString stringWithFormat:@"×%@",_itemModel.count];
    width = [accountStr getSizeOfString:14].width;
    height = 20;
    x = SCREEN_WIDTH - 10 - width;
    _accountLabel.frame = CGRectMake(x, y, width, height);
    _accountLabel.text = accountStr;
    
    //价格
    x = _proImgView.right + 10;
    width = SCREEN_WIDTH - x - _accountLabel.width - 20;
    _priceLabel.frame = CGRectMake(x, y, width, height);
    _priceLabel.text = _itemModel.price;
    
    //线
    x = 10;
    y = _proImgView.bottom + 9;
    width = SCREEN_WIDTH - 2*x;
    height = 1;
    _lineView.frame = CGRectMake(x, y, width, height);
    
    
}
@end
